package com.hsnn.medstgmini.pro.plan.controller;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.hibernate.annotations.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.pro.plan.service.BasePriceadjplanManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.Pagination;

@Controller
@RequestMapping("/basePriceadjplan")
public class BasePriceadjplanController {
	private static final Logger log = Logger.getLogger(BasePriceadjplanController.class);
	
	@Source
	private BasePriceadjplanManager basePriceadjplanManager;

	@Autowired
	public void setBasePriceadjplanManager(BasePriceadjplanManager basePriceadjplanManager) {
		this.basePriceadjplanManager = basePriceadjplanManager;
	}
	@Autowired
	private HttpSession session;

	/**
	 * @category 获取当前登陆人信息
	 * @date 2015年6月14日
	 * @return
	 */
	private SysUser getUser() {
		return (SysUser) session.getAttribute(Constants.USERINFO);
	}
	
	@RequestMapping("/toDataListJsp")
	public String toDataListJsp(HttpServletRequest request) {
		return "/pro/price/settlePriceChangePlan";
	}

	@RequestMapping("/getDataList")
	@ResponseBody
	public Pagination getDataList(HttpServletRequest request) {
		Pagination page = new Pagination(request);
		try {
			String createStartTime = request.getParameter("createStartTime");
			String createEndTime = request.getParameter("createEndTime");
			String executeStartTime = request.getParameter("executeStartTime");
			String executeEndTime = request.getParameter("executeEndTime");
			page.getConditions().put("createStartTime", createStartTime);
			page.getConditions().put("createEndTime", createEndTime);
			page.getConditions().put("executeStartTime", executeStartTime);
			page.getConditions().put("executeEndTime", executeEndTime);
			page.getConditions().put("executeCat", request.getParameter("executeCat"));
			page.getConditions().put("orgId", getUser().getOrgId());
			page.getConditions().put("priceAdjPlanName", request.getParameter("priceAdjPlanName"));
			
			try {
				basePriceadjplanManager.getChangePlan(page);

				page.setSuccess(true);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
}